﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPublisher.Web.Framework;
using VietPublisher.BSL.BK;
using VietPublisher.BaseProject.Models;
using VietPublisher.FileManager;

namespace VietPublisher.Web.BK.Controllers.Admin
{
    public class PublisherController : StringBaseEntityController
    {
        //
        // GET: /Publisher/
        [CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult Index()
        {
            return View();
        }

        [CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult PublisherList()
        {
            List<T_BK_Publisher> publishers = RepoPublisher.GetPublisherList();
            return View("List_Publisher", publishers);
        }

        //
        // Get : /Publisher
        [HttpGet, CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult CreatePublisher()
        {
            return View();
        }


        //
        // Post : /Publisher
        [HttpPost, CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult DoCreatePublisher(FormCollection collection)
        {
            int result = 0;
            try
            {
                string PublisherName = Request.Form["PublisherName"];
                T_BK_Publisher publisher= new T_BK_Publisher(){
                    PublisherName= PublisherName
                };
               result =  RepoPublisher.CreatePublisher(publisher);
            }
            catch (Exception e)
            {
                LogUtility.LogMessage("PublisherController", "DoCreatePublisher", e.Message);
                return Content(result.ToString());
            }
            return Content(result.ToString());
        }


        //
        // Get : /Publisher
        [HttpGet, CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult UpdatePublisher()
        {
            return View();
        }


        //
        // Post : /Publisher
        [HttpPost, CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult DoUpdatePublisher(FormCollection collection)
        {
            return View();
        }


        //
        // Get : /Publisher
        [HttpGet, CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult DeletePublisher(int PublisherID)
        {
            return View();
        }

        /// <summary>
        /// call popup when modify book, this popup can be add publisher to group
        /// or creat new publisher 
        /// </summary>
        /// <returns></returns>
        [CustomAuthorize(Roles = SiteRoles.Admin)]
        public ActionResult OpenPublisherPopup()
        {
            var allPublisher = RepoPublisher.GetPublisherList();
            ViewData["Publisher"] = allPublisher;
            return View();
        }

    }
}
